package com.kkb.dao.impl;

import com.kkb.bean.Grade;
import com.kkb.bean.User;
import com.kkb.dao.GradeDao;
import com.kkb.util.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 班级dao实现
 */
public class GradeDaoImpl implements GradeDao {
    @Override
    public List<Grade> queryAll() {
        List<Grade> list = new ArrayList<>();
        String sql = "select * from t_grade";
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            conn = DBUtils.getConnection();
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()) {
                Grade grade = new Grade();
                grade.setId(rs.getInt("id"));
                grade.setName(rs.getString("name"));
                list.add(grade);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            DBUtils.close(conn, ps, rs);
        }
        return list;
    }
}
